package yunwo.cn.yzstation.model;

import android.widget.Toast;

import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import yunwo.cn.yzstation.api.HttpManager;
import yunwo.cn.yzstation.api.IiventoryActivityModel;
import yunwo.cn.yzstation.api.okapi.GLCallBack;
import yunwo.cn.yzstation.bean.InventoryBean;
import yunwo.cn.yzstation.config.MyConstants;
import yunwo.cn.yzstation.view.activity.InventoryActivity;

/**
 * Created by lao on 2017/9/16.
 */
public class InventoryActivityModel {

    InventoryActivity inventoryActivity;
    IiventoryActivityModel iiventoryActivityModel;

    public InventoryActivityModel(InventoryActivity inventoryActivity, IiventoryActivityModel iiventoryActivityModel) {
        this.inventoryActivity = inventoryActivity;
        this.iiventoryActivityModel = iiventoryActivityModel;
    }

    public void SearchOrder(final String orderstate, String condition, final String data) {
        Map<String, Object> map = new HashMap<>();
        switch (condition) {
            case "收货人":
                map.put("consigneeName", data);
                break;
            case "运单号":
                map.put("trackingNumber", data);
                break;
            case "手机号":
                map.put("consigneePhone", data);
                break;
        }
        switch (orderstate) {
            case "库存":
                map.put("trackingStatus", 0);
                break;
            case "进行中":
                map.put("trackingStatus", 1);
                break;
            case "已完成":
                map.put("trackingStatus", 2);
                break;
        }


        HttpManager.hpptPostPageString(MyConstants.Inventory,1,10,"create_date desc",map).execute(new GLCallBack() {
            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (code == 200) {
                    if (!result.equals("")) {
                        InventoryBean.DataBean dataBean = new Gson().fromJson(result, InventoryBean.DataBean.class);
                        if (dataBean.getList().size() > 0) {
                            iiventoryActivityModel.SearchOrderSuccess(dataBean,orderstate);
                        }
                        else {
                            Toast.makeText(inventoryActivity, "没有查询到改数据", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
                else {
                    Toast.makeText(inventoryActivity, msg, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                Toast.makeText(inventoryActivity,"请求失败", Toast.LENGTH_SHORT).show();
            }
        });

    }
}
